<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Panel extends CI_Controller {
    
    public $ruta_template;

    function __construct(){
        parent::__construct();
        $this->lang->load('lang/pro_'.$this->config->item('language'), $this->config->item('language'));
        $this->load->model('producto_model');
        $this->load->library('form_validation');
        $this->ruta_template = array('ruta' => site_url().'public/'.$this->template->getActiveTemplate(),
                                     'ruta_archivos' => 'templates/traveltemplate/');
        $this->template->write_view('footer', 'footer');
        $this->template->write_view('header', 'header');
        $this->template->write_view('_scripts', 'js', $this->ruta_template);
        $this->template->write_view('_styles', 'css', $this->ruta_template);  
    }

    public function index(){
        $this->load->library('Controlador');
        $this->load->library('General');
        
        if($this->session->userdata('idusuario') == null){
            $this->session->sess_destroy();
            $this->session->sess_create(); 
        }
        if($this->input->post('p_entorno_playa') != ''){ $this->session->set_userdata('p_entorno_playa', $this->input->post('p_entorno_playa')); }
        else{ $this->session->unset_userdata('p_entorno_playa'); }
        if($this->input->post('p_entorno_ciudad') != ''){ $this->session->set_userdata('p_entorno_ciudad', $this->input->post('p_entorno_ciudad')); }
        else{ $this->session->unset_userdata('p_entorno_ciudad'); }
        if($this->input->post('p_entorno_rural') != ''){ $this->session->set_userdata('p_entorno_rural', $this->input->post('p_entorno_rural')); }
        else{ $this->session->unset_userdata('p_entorno_rural'); }
        if($this->input->post('p_entorno_nieve') != ''){ $this->session->set_userdata('p_entorno_nieve', $this->input->post('p_entorno_nieve')); }
        else{ $this->session->unset_userdata('p_entorno_nieve'); }
        if($this->input->post('p_personas') != ''){ $this->session->set_userdata('p_personas', $this->input->post('p_personas')); }
        else{ $this->session->unset_userdata('p_personas'); }
        if($this->input->post('p_valores_lugares') != ''){ $this->session->set_userdata('p_valores_lugares', $this->input->post('p_valores_lugares')); }
        else{ $this->session->unset_userdata('p_valores_lugares'); }
        if($this->input->post('datefrom') != ''){ $this->session->set_userdata('p_datefrom', $this->input->post('datefrom')); }
        else{ $this->session->unset_userdata('p_datefrom'); }
        if($this->input->post('dateto') != ''){ $this->session->set_userdata('p_dateto', $this->input->post('dateto')); }
        else{ $this->session->unset_userdata('p_dateto'); }
        $data['ses'] = $this->valores_sesion();
        
        $pages = 10; //Numero de registros mostrados por páginas
        $this->load->library('pagination'); //Cargamos la librería de paginación
        $config['base_url'] = site_url('busqueda/index'); // parametro base de la aplicación, si tenemos un .htaccess nos evitamos el index.php
        $config['per_page'] = $pages; 
        $config['num_links'] = 3; //Numero de links mostrados en la paginación

        $data['productos'] = $this->producto_model->buscar($config['per_page'], $this->uri->segment(3));
        $config['total_rows'] = $data['productos']->num_rows();
        $config['full_tag_open'] = "<ul class='pagination'>";
        $config['full_tag_close'] = "</ul>";
        $config['next_tag_open'] = "<li class='next'>";
        $config['next_tag_close'] = "</li>";
        $config['prev_tag_open'] = "<li class='prev'>";
        $config['prev_tag_close'] = "</li>";
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        
        $this->pagination->initialize($config); 
        

        $this->template->write_view('content', 'content/resultado', $data);
        $this->template->render();
    }
    
}

?>